function getMyInfo() {
    var data = {
        username: myUsername
    };
    AjaxSubmit("GET", data, basePath + "/teacher/myInfo", getMyInfo_fun);
}

function getMyInfo_fun(res) {
    sessionStorage.setItem("myselfTeacherId", res.id);
    console.log(res);
    if (res.isFamousTeacher != 1) {
        $("#mingShiGongZuoShiGuanLi").hide();
    }
    var account = res.username;
    var teacherType = res.type;
   var birthday = changeTime(new Date(res.birthday));
   /*var birthday = (res.birthday);*/
    var positional = res.positional;
    var duties = res.duties;
    var education = res.education;
    var sex = res.sex;
    $("#headPic").attr("src", res.pic);
    //性别
    if (sex == "F") {
        sex = "女";
    } else if (sex == "M") {
        sex = "男";
    }
    //账户类型
    if (teacherType == "TEACHER") {
        teacherType = "教师";
    } else if (teacherType == "INSTRUCTOR") {
        teacherType = "辅导员";
    } else if (teacherType == "SCHOOLADMIN") {
        teacherType = "校管理员";
    } else if (teacherType == "OTHER") {
        teacherType = "其他";
    }
    //学历
    if (education == "JUNIOR_COLLEGE_STUDENT") {
        education = "专科";
    } else if (education == "UNDERGRADUATE") {
        education = "本科";
    } else if (education == "POSTGRADUATE") {
        education = "硕士";
    } else if (education == "DOCTOR") {
        education = "博士";
    } else if (education == "POST_DOCTORAL") {
        education = "博士后";
    }
    //职称
    if (positional == "PROFESSOR") {
        positional = "教授";
    } else if (positional == "ASSOCIATE_PROFESSOR") {
        positional = "副教授";
    } else if (positional == "LECTURER") {
        positional = "讲师";
    } else if (positional == "INSTRUCTOR") {
        positional = "辅导员";
    }
    //职务
    if (duties == "YUAN_ZHANG") {
        duties = '院长'
    } else if (duties == "FU_YUAN_ZHANG") {
        duties = '副院长'
    } else if (duties == "SHU_JI") {
        duties = '书记'
    } else if (duties == "FU_SHU_JI") {
        duties = '副书记'
    } else if (duties == "KE_YAN_SHI_ZHU_REN") {
        duties = '科研室主任'
    } else if (duties == "XUE_KE_DAI_TOU_REN") {
        duties = '学科带头人'
    } else if (duties == "IDEOLOGICAL_POLITICAL") {
        duties = '思政老师'
    }
    $(".account").html("账号：" + account);
    $(".teacherType").html("类型：" + teacherType);
    $(".table").empty();
    var html = $('<tr>' +
        '<td>姓名：' + (res.teacherName || '') + '</td>' +
        '<td>最后学历：' + (education || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td>学校：' + (res.schoolName || '') + '</td>' +
        '<td>最后学位：' + (res.academicDegree || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td>性别：' + sex + '</td>' +
        '<td>最后毕业大学：' + (res.graduateSchool || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td>出生年月：' + (birthday || '') + '</td>' +
        '<td>学年课时：' + (res.schoolyear || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td colspan="2">职称：' + (positional || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td colspan="2">职务：' + (duties || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td colspan="2">研究方向：' + (res.researchDirection || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td colspan="2">获奖情况：' + (res.awardWinning || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td colspan="2">代表性著作/论文：' + (res.representativeWorksPapers || '') + '</td>' +
        '</tr>' +
        '<tr>' +
        '<td>手机：' + (res.phone || '') + '</td>' +
        '<td>邮箱：' + (res.email || '') + '</td>' +
        '</tr>');
    $(".table").append(html);
    /*编辑框资料显示*/
    console.log(birthday)
    var datebirthday=res.birthday || '';
    $("#teachername").val(res.teacherName);
    $("#education").val(education);
    $("#schoolName").val(res.schoolName);
    $("#academicDegree").val(res.academicDegree);
    $("#sex option[value='" + sex + "']").attr("selected", "selected");
    $("#education option[value='" + education + "']").attr("selected", "selected");
    $("#academicDegree option[value='" + academicDegree + "']").attr("selected", "selected");
    $("#positional option[value='" + positional + "']").attr("selected", "selected");
    $("#duties option[value='" + duties + "']").attr("selected", "selected");
    $("#graduateSchool").val(res.graduateSchool);
    $("#birthday").val(changeTime2(datebirthday));
    $("#schoolyear").val(res.schoolyear);
    $("#positional").val(positional);
    $("#duties").val(duties);
    $("#researchDirection").html(res.researchDirection);
    $("#awardWinning").html(res.awardWinning);
    $("#representativeWorksPapers").html(res.representativeWorksPapers);
    $("#phone").val(res.phone);
    $("#email").val(res.email);
}

function saveMyInfo() {
    var teacherName = $("#teachername").val();//姓名
    var education = $("#education").find("option:selected").attr("data-id");//学历
    var schoolName = $("#schoolName").val();//学校
    var academicDegree = $("#academicDegree").find("option:selected").html();//学位
    var sex = $("#sex").find("option:selected").attr("data-id");//性别
    var graduateSchool = $("#graduateSchool").val();//最后毕业大学
    var birthday = $("#birthday").val();//生日
    var schoolyear = $("#schoolyear").val();//学年课时
    var positional = $("#positional").find("option:selected").attr("data-id");//职称
    var duties = $("#duties").find("option:selected").attr("data-id");//职务
    var researchDirection = $("#researchDirection").val();//研究方向
    var awardWinning = $("#awardWinning").val();//获奖情况
    var representativeWorksPapers = $("#representativeWorksPapers").val();//代表性著作
    var email = $("#email").val();//邮箱
    /*转换*/
    if (academicDegree == '专科生') {
        academicDegree = '';
    }
    var data = {
        username: myUsername,
        teacherName: teacherName,
        education: education,
        schoolName: schoolName,
        academicDegree: academicDegree,
        sex: sex,
        graduateSchool: graduateSchool,
        birthday: birthday,
        schoolyear: schoolyear,
        positional: positional,
        duties: duties,
        researchDirection: researchDirection,
        awardWinning: awardWinning,
        representativeWorksPapers: representativeWorksPapers,
        email: email
    }
    console.log(data);
    $.ajax({
        type: 'GET',
        url: basePath + "/teacher/updateMyInfo",
        data: data,
        dataType: "json",
        success: function (msg) {
            getMyInfo();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest);
            // alert(XMLHttpRequest.responseText);
        }
    });
    $("#myModal").modal("hide");
    
}

/*时间戳转换为年月日*/
function changeTime(timeStr) {
    var date = new Date(timeStr);
    var dateYear = date.getFullYear();
    var dateMonth = date.getMonth() + 1;
    var dateDay = date.getDate();
    var dateStr = dateYear + "-" + dateMonth;
    return dateStr;
}
/*时间戳转换为年月日*/
function changeTime2(timeStr) {
    var date = new Date(timeStr);
    var dateYear = date.getFullYear();
    var dateMonth = date.getMonth() + 1;
    var dateDay = date.getDate();
    var dateStr = dateYear + "-" + dateMonth+ "-" + dateDay;
    return dateStr;
}

